<?php
namespace common\models;

use common\base\BModel;
use Yii;
class YanseTypeModel extends BModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'yanse_type';
    }

    /**
     * @db
     */
    public static function getDb()
    {
        return Yii::$app->get('yanse');
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'source','page','parent','type'], 'integer'],
            [['title','url'], 'string', 'max' => 10],
            [['title','source'], 'unique'],
            [['title','source'], 'required', 'on' => ['add'], 'message' => '{attribute}不能为空'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => '类型名称',
            'source' => '来源 1四虎影库',
            'page' => '最新页码',
            'parent' => '父级id',
            'type' => '1视频 2小说 3图片',
            'url'=> '分类连接'
        ];
    }

    /**
     * 保存前
     * @param bool $insert
     * @return bool
     */
    public function beforeSave($insert)
    {
        if(parent::beforeSave($insert)){
            $time = time();
            if($this->isNewRecord){
                
            }
            return true;
        }
        return false;
    }

}
